package com.jz.community.moduleshoppingguide.neighbor.presenter;

import com.jz.community.basecomm.bean.BaseResponseInfo;
import com.jz.community.basecomm.mvp.BaseLifeCyclePresent;
import com.jz.community.basecomm.net.rxandroid.OnLoadListener;
import com.jz.community.moduleshoppingguide.neighbor.bean.CircleMessageBean;
import com.jz.community.moduleshoppingguide.neighbor.model.NeighborModel;
import com.jz.community.moduleshoppingguide.neighbor.model.NeighborModelImp;
import com.jz.community.moduleshoppingguide.neighbor.ui.NeighborMsgView;

public class NeighborMsgPresenter extends BaseLifeCyclePresent<NeighborMsgView.View> implements NeighborMsgView.Presenter {
    private NeighborMsgView.View view;
    private NeighborModel neighborModel;

    public NeighborMsgPresenter(NeighborMsgView.View view) {
        this.view = view;
        this.neighborModel = new NeighborModelImp(view.getContext());
    }

    @Override
    public void initUserNeighbor() {
        neighborModel.initUserNeighbor(new OnLoadListener<CircleMessageBean>() {
            @Override
            public void onSuccess(CircleMessageBean circleMessageBean) {
                view.isAddCircle(circleMessageBean);

            }

            @Override
            public void onFail(String msg, int code) {
                view.noAddCircle(code);

            }
        });

    }

    @Override
    public void initNeighborMsg(String circleId, String lat, String lon) {
        neighborModel.initNeighborMsg(circleId, lat, lon, new OnLoadListener<CircleMessageBean>() {
            @Override
            public void onSuccess(CircleMessageBean circleMessageBean) {
                view.setNeighborMsgData(circleMessageBean);
            }

            @Override
            public void onFail(String msg, int code) {
                view.showError(msg);

            }
        });

    }

    @Override
    public void addNeighbor(String circleId) {
        neighborModel.addNeighbor(circleId, new OnLoadListener<BaseResponseInfo>() {
            @Override
            public void onSuccess(BaseResponseInfo baseResponseInfo) {
                view.addNeighborSuccess();
            }

            @Override
            public void onFail(String msg, int code) {
                view.addNeighborFail(msg);

            }
        });

    }

    @Override
    public void quitNeighbor(String circleId) {
        neighborModel.quitNeighbor(circleId, new OnLoadListener<BaseResponseInfo>() {
            @Override
            public void onSuccess(BaseResponseInfo baseResponseInfo) {
                view.quitNeighborSuccess();
            }

            @Override
            public void onFail(String msg, int code) {
                view.quitNeighborFail(msg);

            }
        });

    }
}
